<?php
class Web_Form_Contact 
	extends Zend_Form
{
	private $_pubkey; 
	private $_privkey; 
	private $_asuntos = array(
		'reportProblem',
		'leaveComment',
		'askQuestion',
		'addMyCommerce',
		'...'
	); 
	
	public function __construct($options=null) {
		
		if (isset($options['pubkey'])){
			$this->_pubkey = $options['pubkey'];
			unset($options['pubkey']);
		}
		
		if (isset($options['privkey'])){
			$this->_privkey = $options['privkey'];
			unset($options['privkey']);
		}
		
		parent::__construct($options);
	}
	
	public function init()
	{				
	
		$this->setMethod('post');
		$this->setName('contactForm');
		
		$nombre = new Zend_Form_Element_Text('nombre');
		$nombre->setLabel('name');
		$nombre->setRequired(true);
		$nombre->addValidator(new Zend_Validate_StringLength(2, 100));		
				
		$this->addElement($nombre);
		
		
		$email  = new Zend_Form_Element_Text('email');
		$email->setLabel('email');
		$email->setRequired(true);
		$email->addValidator(new Zend_Validate_EmailAddress());
				
		$this->addElement($email);
						
		$telefono = new Zend_Form_Element_Text('telefono');
		$telefono->setLabel('phone');
		$telefono->setRequired(true);
		$telefono->addValidator(new Zend_Validate_StringLength(6, 15));		
				
		$this->addElement($telefono);
		
		
		$asuntos = array();
		$translate = $this->getTranslator();
		foreach($this->_asuntos as $a){
			$m = $translate->_($a);
			$asuntos[] = $m;
		}
		
		$asunto = new Zend_Form_Element_Select('asunto');
		$asunto->addMultiOptions( array_combine( $asuntos, $asuntos) );
		$asunto->setLabel('iWouldLike');
		$asunto->setRequired(true);
				
		$this->addElement($asunto);
		
		$mensaje = new Zend_Form_Element_Textarea('mensaje');
		$mensaje->setLabel('message');
		$mensaje->setRequired(true);
		$mensaje->addValidator(new Zend_Validate_StringLength(10, 1000));
		
		$this->addElement($mensaje);
	    
	    $this->addElement('captcha', 'captcha', array(
	        'required' => true,
	        'captcha' => array(
	            'pubkey'	=> $this->_pubkey,
	            'privkey'	=> $this->_privkey,
	            'captcha'	=> 'reCaptcha',
				'lang'		=> 'es',
				'theme'		=> 'white'
	        )
	    ));
			
		
		$submit = new Zend_Form_Element_Submit('submit');
		$submit->setLabel('send');
		$this->addElement($submit);
	
	}
	
	public function loadDefaultDecorators()	{
		
		$elements = $this->getElements();
		unset($elements['submit']);
		
		$this->addDecorator('FormElements')
			->addDecorator('HtmlTag', 	array('tag' => 'div', 'class' => 'zend_form'))
			->addDecorator('Form')
			->setElementDecorators(array(
				array('ViewHelper'),
				array('Errors',			array('placement' => 'APPEND')),
				array('Description', 	array('tag' => 'em', 'class' => 'element-description', 'placement' => 'APPEND')),
				array('Label', 			array('separator' => ' ', 'placement' => 'PREPEND')),
				array('HtmlTag', 		array('tag' => 'div', 'class' => 'element')),
				),
				array_keys($elements)
			);	

		$this->setElementDecorators(array(
				array('ViewHelper'),				
				array('HtmlTag', 		array('tag' => 'div', 'class' => 'submit-group')),
				),
				array('submit')
			);
	
	}



}